package com.atguigu.day26.problem03;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/*

MySQL规定的单次上传最大的数据包 4M
MySQL安装路径下 数据目录 my.ini  max_allowed_packet

 */
public class PhotoTest {
    @Test
    public void test01() throws SQLException, IOException {

        //1.注册驱动
        //2.获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql:///atguigu", "root", "1234");
        //3.准备sql
        String sql = "insert into t_photo values(null,?,?)";
        //4.创建命令发送器
        PreparedStatement pst = connection.prepareStatement(sql);
        //5.填充数据
        pst.setObject(1,"tom猫");
       // FileInputStream fis = new FileInputStream("C:\\imgs\\future.jpg");
        FileInputStream fis = new FileInputStream("C:\\Users\\xiaoma\\Pictures\\Saved Pictures\\steve.png");
        pst.setObject(2,fis);
      //  pst.setBlob(2,fis);
        //6.执行命令
        pst.executeUpdate();
        //7.关闭资源
        fis.close();
        pst.close();
        connection.close();
    }
}
